package com.guet.niit.Login.service;

import com.guet.niit.Login.dao.UserDao;
import com.guet.niit.Login.dao.UserDaoImpl;
import com.guet.niit.Login.pojo.Account;
import com.guet.niit.Login.pojo.User;
import com.guet.niit.Login.pojo.UserCar;
import javafx.scene.control.Alert;

import java.util.List;

public class UserService {
    private UserDao userDao = new UserDaoImpl();

    /**
     * 查询用户信息
     * @return
     */
    public User selectUserInfo(Long id) {
        User users = userDao.selectUserInfo(id);
        return users;
    }

    /**
     * 用户上传图片
     * @param user
     */
    public String userUpload(User user){
        String status = null;
        int count = userDao.userUpload(user);
        if (count>0){
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setHeaderText(null);
            alert.setContentText("更换成功！");
            alert.showAndWait();
            status = "success";
        }
        return status;
    }

    /**
     * 查询用户账户信息
     * @param id
     * @return
     */
    public Account selectAccount(Long id){
        Account account = userDao.selectAccount(id);
        return account;
    }

    /**
     * 新增用户账户
     * @param account
     */
    public void AddAccount(Account account) {
        userDao.AddAccount(account);
    }

    /**
     * 修改用户名字
     * @param user
     * @return
     */
    public void updateUserName(User user) {
        int status = userDao.updateUserName(user);
        if (status==1){
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setHeaderText(null);
            alert.setContentText("修改成功！");
            alert.showAndWait();
        }
    }

    /**
     * 修改用户电话
     * @param account
     * @return
     */
    public void updatePhone(Account account) {
        int status = userDao.updatePhone(account);
        if (status==1){
            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.setHeaderText(null);
            alert.setContentText("修改成功！");
            alert.showAndWait();
        }
    }

    /**
     * 查询用户拥有车辆
     * @param id
     * @return
     */
    public List<UserCar> selectUserCar(Long id) {
        List<UserCar> userCars = userDao.selectUserCar(id);
        return userCars;
    }
}
